package com.example.zjhuojback.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result {
    public static final String CODE_SUCCESS = "200";
    public static final String CODE_AUTH_ERROR = "401";
    public static final String CODE_SYS_ERROR = "500";

    /**
     * 请求返回编码
     * 表示成功还是失败401
     * msg表示错误信息
     */
    private String code;
    private String msg;
    private Object data;
    private Object data2;
    private long totalPages; // 总页数
    public static Result success() {
        return new Result(CODE_SUCCESS, "请求成功", null, null, 0);
    }
    public static Result success(Object data) {
        return new Result(CODE_SUCCESS, "请求成功", data, null, 0);
    }

    public static Result success(Object data, Object data2) {
        return new Result(CODE_SUCCESS, "请求成功", data, data2, 0);
    }
    // 返回数据、总页数和总记录数
    public static Result success(Object data, long totalPages) {
        return new Result(CODE_SUCCESS, "请求成功", data, null, totalPages);
    }

    public static Result error(String msg) {
        return new Result(CODE_SYS_ERROR, msg, null, null, 0);
    }
    public static Result error(String code, String msg) {
        return new Result(code, msg, null, null, 0);
    }
    public static Result error() {
        return new Result(CODE_SYS_ERROR, "系统错误", null, null, 0);
    }
}
